package com.yizhang.annotation.service.impl;


import com.yizhang.annotation.entity.User;
import com.yizhang.annotation.mapper.UserMapper;
import com.yizhang.annotation.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("userService")
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public void show() {
        // 这里为啥aop没失效，没找到原因
        this.query();
    }

    @Override
    public void query() {
        List<User> list = userMapper.findAll();
        for (User user : list) {
            System.out.println(user);
        }
    }

    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ, rollbackFor = Exception.class)
    public void transfer() {
        userMapper.transfer("zhangyi", 500);
        int i = 1/0;
        userMapper.transfer("lisi", -500);
    }
}
